package org.example.Frame;

import org.example.Pojo.User;
import org.example.implement.MyFrame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;

public class Difficulty extends JFrame implements MyFrame {
    //变量
   private JButton button1;
   private JButton button2;
   private JButton button3;
   private int difficulty;
   private User player;//玩家信息
   //初始化
    public Difficulty(User player){
        //初始化界面
        this.setSize(400,400);
        this.setTitle("难度选择");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //变量初始化
        this.player=player;
        //利用绘画板进行组件初始化
        JPanel panel=new JPanel();
        draw(panel);
        this.add(panel);
        this.setVisible(true);

    }
    //绘画板
    @Override
    public void draw(JPanel panel){
        panel.setLayout(null);

        button1=new JButton("简单");//简单模式的按钮
        button1.setBounds(50,160,80,40);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                difficulty=0;
                close();
            }
        });
        panel.add(button1);

        button2=new JButton("中等");//中等难度的按钮
        button2.setBounds(150,160,80,40);
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                difficulty=1;
                close();
            }
        });
        panel.add(button2);

        button3=new JButton("困难");//困难难度的按钮
        button3.setBounds(250,160,80,40);
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                difficulty=2;
                close();
            }
        });
        panel.add(button3);
    }

    @Override
    public void close(){
        this.setVisible(false);
        new ImageChoose(difficulty,player);
    }

}
